
package com.wanger.swc.exception;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @Author: wanger
 * @Date: 2024/9/15 19:45
 * @Description: 自定义业务异常
 */
@Data
@SuppressWarnings("unused")//抑制未使用方法警告
@EqualsAndHashCode(callSuper = true)
public class BusEx extends RuntimeException {
    private static final long serialVersionUID = 7436228843062266440L;

    private String msg;
    private int code = 500;

    public static void throwEx(String message) {
        throw create(message);
    }

    public static void throwEx(String message, Object... params) {
        throw create(message, params);
    }

    public static void throwEx(String message, Throwable e) {
        throw create(message, e);
    }

    public static BusEx create(String message) {
        return new BusEx(message);
    }

    public static BusEx create(String message, Object... params) {
        return new BusEx(StrUtil.format(message, params));
    }

    public static BusEx create(String message, Throwable e) {
        return new BusEx(message, e);
    }

    public BusEx(String msg) {
        super(msg);
        this.msg = msg;
    }

    public BusEx(String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
    }

    public BusEx(String msg, int code) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public BusEx(String msg, int code, Throwable e) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
    }

}
